package com.ygxsk.carhome.ui;


import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;

import com.trello.rxlifecycle4.components.support.RxFragment;

public class FragmentEventSK extends RxFragment {
//public class FragmentEvent extends Fragment {

    public interface OnEventListener {

        void onEvent(int what, Bundle data, Object object);

    }

    protected OnEventListener onEventlistener = null;

    private Context mContext;

    @Override
    public Context getContext() {
        return mContext;
    }

    //=====================================================================================================================

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {

            if (activity != null) {//这个时候可能Activity可能没有创建完毕。

                if (activity instanceof OnEventListener) {
                    try {
                        onEventlistener = (OnEventListener) activity;

                    } catch (ClassCastException e) {
                        throw new ClassCastException(activity.toString() + "must implement " + OnEventListener.class);
                    }
                } else {
                    throw new ClassCastException(activity + "must implement " + OnEventListener.class);
                }
            }
        }

    }

    //2017年1月15日因为OrderFragment内存溢出故添加
    @Override
    public void onAttach(Context context) {

        this.mContext = context;

        if (context instanceof OnEventListener) {
            onEventlistener = (OnEventListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnEventListener");
        }

        super.onAttach(context);
    }


    //2017年03月测试内存泄露的时候放开
	/*@Override
	public void onDestroy() {
		super.onDestroy();

		RefWatcher refWatcher = DgjApplication.getRefWatcher(getActivity());
		refWatcher.watch(this);

	}*/


}
